
from flask import current_app
import redis


class RedisOper():
    def __init__(self):
        host = current_app.config.get('REDIS_HOST')
        port = current_app.config.get('REDIS_PORT')
        db = current_app.config.get('REDIS_DB')
        pwd = current_app.config.get('REDIS_PWD')
        self.rds = redis.Redis(host=host,port=port,db=db,password=pwd)

    def set_v(self, data, expire, value):
        print("data>", data, "expire>", expire, "value>", value)
        self.rds.setex("data_%s"%data, expire, value)

    def get_v(self, data):
        print("data>", data)
        return self.rds.get("data_%s"%data)


